// pages/payorder/payorder.js
const api = require("../../api/api")
const app = getApp()
Page({

    /**
     * 页面的初始数据
     * 
     */
    data: {
      id: '', //当前选择商品订单的id
      goodsDetailMsg: [],
      img: [],
      time:0,
      price:0,
      buyer_id:'', //目前登录者的ID
      sender_id:'',//发布该商品订单的人的ID
      owner:false
      
    },
    getGoods() {
      wx.request({
            url: api.getGoodsDetail.url,
            method: api.getGoodsDetail.method,
            data: {
              id: this.data.id,
            },
            success: res => {
              console.log(res)
              var info = res.data.data[0].img.split('|')
              this.setData({
                goodsDetailMsg: res.data.data[0],
                time:res.data.data[0].viewCount,
                img:info,
                price: parseInt(res.data.data[0].price)*100,
                sender_id:res.data.data[0].senderId
              })
              if(this.data.buyer_id == this.data.sender_id){
                this.setData({
                  owner:true
                })
              } 
              console.log(this.data.goodsDetailMsg)
              console.log(this.data.img)
            },
        })
    },
    onSubmit(){
      if (!app.globalData.isLogin) {
        wx.showToast({
          title: '请登录后操作',
          icon: "none"
        })
        return
      }
      wx.navigateTo({
        url: '../../pages/goodsOrder/goodsOrder?id='+this.data.id,
      })
      
    },
    onLoad: function (options) {
      
      wx.request({
        url: api.viewGoods.url,
        method:api.viewGoods.method,
        data:{
          id:options.id
        },
        success:res=>{
        
        }
      })
      console.log(options.id)
      this.setData({
        id: options.id,
        buyer_id:app.globalData.id
      })
      this.getGoods() 
         
      console.log(this.data.owner)
    },
   
})